Proto tx messages deduplicator#1728
Merged
Merged
Conversation
70b60c8 to
f68200d
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a message deduplication mechanism for transaction-related proto messages, refactors message handling in the Node, and adds tests to ensure the correctness of the new behavior.
- Introduces a thread‑safe map (safeMap) and payload filtering logic in pkg/node/helpers.go.
- Updates the Node Run method in pkg/node/node.go to utilize the new deduplication mechanism.
- Adds unit tests in pkg/node/helpers_internal_test.go to verify deduplication of duplicate transaction messages.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/p2p/peer/handle.go | Added a clarifying comment regarding context cancellation. |
| pkg/node/node.go | Refactored to use deduplicateProtoTxMessages and updated metrics. |
| pkg/node/helpers_internal_test.go | Introduced unit tests for deduplication functionality. |
| pkg/node/helpers.go | Implemented safeMap and deduplication support; potential issue noted. |
Comments suppressed due to low confidence (1)
pkg/node/helpers.go:188
- The 'max' function appears to be used without a definition or import. Please ensure that 'max' is defined or replace it with an appropriate alternative for determining the channel buffer size.
filteredChan := make(chan protoMessageWrapper, max(cap(origMessageCh)-noFilteredChanSize, noFilteredChanSize))
alexeykiselev
previously approved these changes
Jun 19, 2025
alexeykiselev
approved these changes
Jun 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a message deduplication mechanism for
peer.ProtoMessageobjects, refactors message handling in theNodeclass, and adds tests to ensure the correctness of the new functionality. The changes aim to improve efficiency by filtering out duplicate transaction messages and simplifying the internal metrics tracking.Message Deduplication and Filtering:
pkg/node/helpers.go: AddedsafeMapfor thread-safe storage and deduplication of messages, and implementeddeduplicateProtoMessagesanddeduplicateProtoTxMessagesfunctions to filter duplicate transaction messages using a message ID filter based on its payloads. These functions ensure that only unique transaction messages are processed while bypassing non-transaction messages.Refactoring in
Node:pkg/node/node.go: Updated theRunmethod to use the new deduplication mechanism (deduplicateProtoTxMessages) for processingpeer.ProtoMessageobjects. This refactor replaceschanLenProviderwithaggregatedLenProviderfor improved metrics tracking. [1] [2] [3]Testing:
pkg/node/helpers_internal_test.go: Added unit tests fordeduplicateProtoTxMessagesto verify that duplicate transaction messages are filtered out while non-transaction messages remain unaffected. The tests use mock data and assertions to ensure correctness.Minor Improvements:
pkg/p2p/peer/handle.go: Added a clarifying comment to explain the behavior of context cancellation in theHandlefunction.